<template>
  <div class="content-box">
    <nav-title title="培训经历" />
    <div class="line">
      <span class="important"></span>
      <div class="label">开始时间</div>
      <div class="value">
        <group>
          <datetime value-text-align="left" readonly placeholder="请选择" v-model="trains.startDt"></datetime>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">结束时间</div>
      <div class="value">
        <group>
          <datetime value-text-align="left" readonly placeholder="请选择" v-model="trains.endDt"></datetime>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">培训机构</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="trains.cCompany" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">培训内容</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="trains.cDescr" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">有无证书</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" readonly :options="lcList" v-model="trains.cYesNo1"></popup-radio>
        </group>
      </div>
    </div>
    <div class="submit-btn" @click="save" v-if="showOr">
      保存
    </div>
    <div class="remove-btn" @click="remove" v-if="showOr">
      删除
    </div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import { savePTra,delTraining } from '../../../api/api'
import { json2Form } from '../../../util/http'

export default {

  name: 'input-information',
  components: {
    Datetime, Group, PopupRadio
  },
  data() {
    return {
      trains:{
        startDt:'',
        emplid: '',
        cModStauts:'',
        cTransactionNbr:''
      },
      showOr:true,
      lcList: [{value: '有', key: 'Y'},{value: '无', key: 'N'}],

    }
  },
  created() {
    this.gettrain()
    if(this.$route.params.cnta){
      this.trains.cTransactionNbr = this.$route.params.cnta
    }
  },
  methods: {
    save() {
      if(this.trains.cModStauts == 'U'){
        this.trains.cModStauts = 'U'
      }else{
        this.trains.cModStauts = 'C'
      }
      // if(this.beginDate === ''){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请选择开始时间'
      //   });
      //   return;
      // }

      // if(this.endDate === ''){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请选择结束时间'
      //   });
      //   return;
      // }

      // if(this.company === ''){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请输入培训机构'
      //   });
      //   return;
      // }

      // if(this.descr === ''){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请输入培训内容'
      //   });
      //   return;
      // }

      // if(this.certificate.length === 0){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请选择有无证书'
      //   });
      //   return;
      // }
      console.log(this.trains)
      savePTra(json2Form(this.trains)).then(res => {
        const that = this;
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          this.$vux.alert.show({
            title: '新城',
            content: '保存成功',
            onHide () {
              that.$router.push({
                name: 'userBase',
                params:{
                  cnta: that.trains.cTransactionNbr
                }
              });
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },
    remove() {
      this.trains.cModStauts = 'D'
      const _this = this;
      this.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            savePTra(json2Form(_this.trains)).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                //删除成功
                _this.$vux.alert.show({
                  title: '新城',
                  content: '删除成功',
                  onHide () {
                    _this.$router.push({
                    name: 'userBase',
                    params:{
                      cnta: _this.trains.cTransactionNbr
                    }
                  });
                  }
                })
              }else{
                // 显示
                _this.$vux.alert.show({
                  title: '',
                  content: res.retMsg
                })
              }

            })
            .catch(res=>{
              _this.$vux.alert.show({
                title: '',
                content: '网络异常，请稍后重试'
              })
            })
            
          }
        })
    },
    gettrain() {
      if(this.$route.params.tralt){
        this.trains = this.$route.params.tralt
        // this.trains.startDt = this.$route.params.tralt.startDt
        // this.trains.endDt = this.$route.params.tralt.endDt
        // this.trains.cCompany = this.$route.params.tralt.cCompany
        // this.trains.cDescr = this.$route.params.tralt.cDescr
        // this.trains.cYesNo1 = this.$route.params.tralt.cYesNo1

        // this.trains.cSeqno = this.$route.params.tralt.cSeqno
        // this.trains.cTransactionNbr = this.$route.params.ctn
        // this.trains.cModStauts = this.$route.params.cModStauts
        if(!this.$route.params.ctn){
          this.showOr = false
        }
      }
    }
  }
}
</script>
<style type="text/scss" lang="scss" scoped>
@import "./personstyle";
</style>
